package com.driver.fordriver.fragment;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.driver.fordriver.R;
import com.driver.fordriver.activity.ViewActivity;
import com.driver.fordriver.util.XywUtil;
import com.mob.commons.SHARESDK;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;
import solid.ren.skinlibrary.loader.SkinInflaterFactory;

/**
 * Created by XuYeWen on 2017/12/25.
 */

public class ShareFragment extends BaseFragment implements View.OnClickListener {

    private Button bt1;
    private Button bt2;
    private ImageView iv1;
    private ImageView iv2;
    @BindView(R.id.iv_change3)
    ImageView iv3;
    @BindView(R.id.tv_change1)
    TextView tv1;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_share_layout, container, false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        ButterKnife.bind(this,view);
        bt1= (Button) view.findViewById(R.id.bt_share1);
        bt2= (Button) view.findViewById(R.id.bt_share2);
        iv1= (ImageView) view.findViewById(R.id.iv_change1);
        iv2= (ImageView) view.findViewById(R.id.iv_change2);
        bt1.setOnClickListener(this);
        bt2.setOnClickListener(this);
        iv1.setOnClickListener(this);
        iv2.setOnClickListener(this);
        iv3.setOnClickListener(this);
        tv1.setOnClickListener(this);
//        dynamicAddView(iv3,"drawableTop",R.drawable.tuotu_selector_changevoice);
//        SkinInflaterFactory factory=getSkinInflaterFactory();
//        factory.dynamicAddSkinEnableView(getActivity(),iv1,"myIndicatorAttr",R.drawable.tv_device_press);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.bt_share1:
                XywUtil.log("click bt_share1");
                share1();
                break;
            case R.id.bt_share2:
                XywUtil.log("click bt_share2");
                share2();
                break;
            case R.id.iv_change1:
                XywUtil.log("click iv_change1");
                XywUtil.reStoreSkinTheme();
                break;
            case R.id.iv_change2:
                XywUtil.log("click iv_change2");
                XywUtil.onSkinSetClick(getActivity());
                break;
            case R.id.iv_change3:
                XywUtil.log("click iv_change3");
                break;
            case R.id.tv_change1:
                XywUtil.log("click tv_change1");
                break;
        }
    }

    private void share1(){
        OnekeyShare oks = new OnekeyShare();

        oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
        oks.setTitleUrl("http://www.baidu.com");
        oks.setText("text");
        oks.setTitle("标题");

//        oks.setPlatform(QQ.NAME);
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                XywUtil.log("share onComplete");
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                XywUtil.log("share onComplete");
            }

            @Override
            public void onCancel(Platform platform, int i) {
                XywUtil.log("share onComplete");
            }
        });
        oks.show(this.getContext());
    }

    private void share2(){
        Platform.ShareParams params=new Platform.ShareParams();
        Bitmap logo= BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
        params.setShareType(Platform.SHARE_IMAGE);
        params.setImageData(logo);
//        params.setUrl("http://www.baidu.com");
//        params.setTitleUrl("http://www.baidu.com");
        params.setText("text");
        params.setTitle("标题");
//        Platform weixin= ShareSDK.getPlatform(Wechat.NAME);
        Platform weixin= ShareSDK.getPlatform(WechatMoments.NAME);
        weixin.share(params);
        weixin.setPlatformActionListener(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                XywUtil.log("share2 onComplete");
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                XywUtil.log("share2 onError");
            }

            @Override
            public void onCancel(Platform platform, int i) {
                XywUtil.log("share2 onCancel");
            }
        });
    }
}
